# coding: utf8
# datetime: 2021-03-31
# 题目地址: https://leetcode-cn.com/problems/subsets-ii/


from typing import List
import copy


class Solution:
    def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
        res = []
        self.dfs(nums, 0, res, [])
        return res
    
    def dfs(self, nums, index, res, path):
        path = sorted(path)
        if path not in res:
            res.append(path)
        for i in range(index, len(nums)):
            self.dfs(nums, i + 1, res, path + [nums[i]])


a = Solution()
print(a.subsetsWithDup([1,2,2]))
